USE DB_TCC
IF EXISTS(SELECT 1 FROM SYSOBJECTS WHERE NAME LIKE 'P_PERGUNTA_LISTAR')
	DROP PROCEDURE P_PERGUNTA_LISTAR
GO
CREATE PROCEDURE P_PERGUNTA_LISTAR(
	@IDPERGUNTA		INTEGER,
	@TIPOPERGUNTA	CHAR(1),
	@OBRIGATORIO	CHAR(1),
	@PADRAO			CHAR(1))
AS BEGIN
	SELECT
		IDPERGUNTA,
		IDAREA,
		DESCPERGUNTA,
		TIPOPERGUNTA,
		OBRIGATORIO,
		PADRAO,
		ATIVO,
		USUARIOINCLUSAO,
		DTHRINCLUSAO,
		USUARIOALTERACAO,
		DTHRALTERACAO
	FROM
		PERGUNTA
	WHERE
		(IDPERGUNTA = @IDPERGUNTA OR @IDPERGUNTA = 0)
		AND (TIPOPERGUNTA = @TIPOPERGUNTA OR CONVERT(CHAR(1), @TIPOPERGUNTA) IS NULL)
		AND (OBRIGATORIO = @OBRIGATORIO OR CONVERT(CHAR(1), @OBRIGATORIO) IS NULL)
		AND (PADRAO = @PADRAO OR CONVERT(CHAR(1), @PADRAO) IS NULL)
		AND ATIVO = 'S'
END